﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy3_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            try
            {
                // 读取输入框数据并转换为double
                double x = Convert.ToDouble(txtX.Text);
                double y = Convert.ToDouble(txtY.Text);
                double r = Convert.ToDouble(txtR.Text);

                // 创建Circle对象并赋值
                Circle circle = new Circle();
                circle.SetValue(x, y, r);

                // 计算并四舍五入到小数点后两位
                double area = Math.Round(circle.GetArea(), 2);
                double perimeter = Math.Round(circle.GetPerimeter(), 2);
                double distance = Math.Round(circle.GetDistance(), 2);

                // 显示结果
                txtArea.Text = area.ToString();
                txtPerimeter.Text = perimeter.ToString();
                txtDistance.Text = distance.ToString();
            }
            catch (Exception ex)
            {
                // 处理输入错误（如非数字）
                MessageBox.Show("请输入有效的数字！\n" + ex.Message, "错误");
            }
        }
    }
}